import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.ww.config.MainDataSourceConfig;

import javax.sql.DataSource;

public class IOCTestProfile {

    @Test
    public void test01(){
        /**
         * 1、激活某环境需要添加启动参数-Dspring.profiles.active=prod
         * 2、使用代码进行激活某个环境
         */
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
        ConfigurableEnvironment environment = applicationContext.getEnvironment();
        environment.setActiveProfiles("dev");
        applicationContext.register(MainDataSourceConfig.class);
        applicationContext.refresh();

        String[] names = applicationContext.getBeanNamesForType(DataSource.class);
        for(String name:names){
            System.out.println(name);
        }

    }
}
